# 1创建列表
# (1)直接等于值，用中括号包裹
list1=[]
list2=['hello','world']
print(list1,type(list1))
print(list2,type(list2))
print('------------------')
# (2)使用list()方法改变类型
list1=list('hello')
print(list1,type(list1))
print('------------------')
# 2列表的访问
# (1)下表（索引）
list1=['hello','world',"I'm",'fine']
print(list1[1])
# (2)切片方式
print(list1[0:4:2])#开始位置：结束位置：步长，前闭后开
print(list1[:2])
print(list1[0:2])
print('----------')
# (3)for遍历访问
for i in list1:
    print(i)
# 3列表内容操作
# (1)新增
# append()追加单个值
# extend()追加多个值
# inster()插入列表
list1=['hello','world',"I'm",'fine']
list2=['张三','李四',"王五",'赵六']
list1.append(list2)
print(list1)
print('+++++++++++++')
list1=['hello','world',"I'm",'fine']
list2=['张三','李四',"王五",'赵六']
list1.extend(['extend1','extend2'])
print(list1)
print('+++++++++++++')
list1=['hello','world',"I'm",'fine']
list1.insert(0,'first')
print(list1)
print('+++++++++++++')
list1=['hello','world',"I'm",'fine']
list2=['张三','李四',"王五",'赵六']
list1.insert(0,list2)
print(list1)
print('+++++++++++++')
# (2)列表内容删除
# pop()：删除单个值
# del ：与pop删除方式相同，通过下表删除，不同点是，del不带下表可以删除整个列表
# remove()通过内容删除
# clear()：清除列表内所有内容，但列表还在
list1=['hello','world',"I'm",'fine']
list1.pop(0)
print(list1)
list1=['hello','world',"I'm",'fine']
del list1[0]
print(list1)
list1=['hello','world',"I'm",'fine']
del list1
# print(type(list1))
list1=['hello','world',"I'm",'fine']
list1.remove("world")
print(list1)
list1.clear()
print(list1)
print("**************************")
# (3)内容修改:直接重新赋值或下表的方式
list1=['hello','world',"I'm",'fine']
print(list1)
list1[1]='world!!!'
print(list1)
print("**************************")

# 4列表排序
# sort(参数1，参数2)参数1：排序方式，参数2：顺序还是逆序，默认顺序
# sorted()：新生成一个列表，
# reversed()
list1=['hello','world',"I'm",'fine']
print(list1)
list1.sort(key=len,reverse=False)
print(list1)
list1=['hello','world',"I'm",'fine']
